<?php

namespace services;
use fast\Http;
class ElemService{
    const AppKey="34347131";
    const AppSecret="34456406be51e1761efe8f10b95ba2c0";
    const version="2.0";
    protected $method='AES-128-ECB';
    protected $aes_options=0;
    protected $iv='';
    protected $is_hex=true;   // 要求输出格式为HEX
    protected $timestamp = null;
    public $pid = 'alsc_18205279_2156054_5686241';
    public $sid = '100';
    public $url = null;
    public function __construct($pid=''){
        $this->timestamp = time();
        // $this->pid = $pid??$this->pid;
    }


    
    /**
     * 活动取链
     * @DateTime 2023-04-18T14:24:51+0800
     * @param    [type]                   $pid 请求Id，媒体方生成，不超过32位
     * @param    [type]                   $utmMedium 二级渠道标识（必须AES加密）
     * @return   [type]                              [description]
     */
    // public function getActivityLink()
    // {
    //     $this->url = 'https://eco.taobao.com/router/rest';
    //     $method = 'alibaba.alsc.union.promotion.link.analyze';
    //     $query = [
    //       'method' => $method,
    //       'app_key' => self::AppKey,
    //       'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
    //       'v' => self::version,
    //       'sign_method' => 'hmac',
    //       'format' => 'json',
    //     ];
    //     $param['query_request'] = [
    //       'pid' => $this->pid,
    //       'shop_id' => $this->encrypt(1)
    //     ];
    //     $sign = $this->sign($query, $param);
    //     $query['sign'] = $sign;
    //     $url = $this->url.'?'.http_build_query($query);
    //     $params = json_encode($param);
    //     $header = array('Content-Type: application/json; charset=utf-8','Content-Length:' . strlen($params));
    //     $res = Http::post($url,$params,[],$header);
    //     var_dump($res);exit;
    // }

    // aes加密
    public function encrypt($data,$key='')
    {
        empty($key) && $key=self::AppKey;
        $base64=openssl_encrypt($data, $this->method, $key, $this->aes_options, $this->iv);
        return $this->is_hex ? bin2hex(base64_decode($base64)) : $base64;
    }

    // 签名
    public function sign($query, $param)
    {
      $param = array_merge($query,$param);
      ksort($param);
      $md5str = '';
      foreach ($param as $key => $value) {
          if(!is_array($value) && "@" != substr($value, 0, 1))
          {
            $md5str .= $key.$value;
          }
      }
      // $sign = hash_hmac('md5', $md5str, self::AppSecret);
      $sign = strtoupper(md5(self::AppSecret.$md5str.self::AppSecret));
      return $sign;
    }


    
    /**
     * 订单列表
     * @DateTime 2023-04-18T14:24:51+0800
     * @param    [type]                   $pid 请求Id，媒体方生成，不超过32位
     * @param    [type]                   $utmMedium 二级渠道标识（必须AES加密）
     * @return   [type]                              [description]
     */
    public function getOrderList($param)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.kbcpx.positive.order.get';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
        ];
        $sign = $this->sign($query, $param);
        $query['sign'] = $sign;
        $url = $this->url.'?'.http_build_query($query);
        // $params = json_encode($param);
        // $header = array('Content-Type: application/json; charset=utf-8','Content-Length:' . strlen($params));
        $header = [];
        $res = Http::get($url,$param,[],$header);
        return $res;
    }



    // {
    //   "latitude": "31.201453",
    //   "biz_type": "activityCps|ordinaryCps",
    //   "pid": "alsc_18205279_2156054_5686241",
    //   "sid": "100",
    //   "longitude": "121.460080",
    //   "page_size": 20
    // }
    public function getShopList($param = [])
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.promotion.storepromotion.query';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param['pid'] = $this->pid;
        $param['sid'] = $this->sid;
        $json = json_encode($param,1);
        $params['query_request'] = $json;
        $sign = $this->sign($query, $params);
        $query['sign'] = $sign;
        $query = array_merge($query,$params);
        $url = $this->url.'?'.http_build_query($query);
        // $params = json_encode($param);
        // $header = array('Content-Type: application/json; charset=utf-8','Content-Length:' . strlen($params));
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }
    
    public function check($order_id)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.tool.order.attrbute.check';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param['order_id'] = $order_id;
        $json = json_encode($param,1);
        $params['query_request'] = $json;
        $sign = $this->sign($query, $params);
        $query['sign'] = $sign;
        $query = array_merge($query,$params);
        $url = $this->url.'?'.http_build_query($query);
        // $params = json_encode($param);
        // $header = array('Content-Type: application/json; charset=utf-8','Content-Length:' . strlen($params));
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }
    //{"alibaba_alsc_union_eleme_storepromotion_reviewbwc_query_response":{"biz_error_code":"0","data":{"records":{"review_bwc_store_promotion_dto":[{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"310","commission_rate":"0.06","daily_remain_stock":3,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2000","start_time":1703766925}]},"category_1_id":"220","category_1_name":"中式菜系","delivery_distance":1483,"delivery_price_cent":3000,"delivery_time":40,"indistinct_monthly_sales":"1000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=ae30645d55d9412ba909c66510deba0d"},"service_rating":"4.9","shop_id":"7FA0170E9908ADED698543BB211B05D6","shop_name":"大城小厨私房菜","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i3\/2215760595906\/O1CN01Obp1So1tV0058aK7K_!!2215760595906-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"206","commission_rate":"0.06","daily_remain_stock":4,"daily_stock":5,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"2500","start_time":1714492800}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":1483,"delivery_price_cent":0,"delivery_time":25,"indistinct_monthly_sales":"5000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=14a002a3ca6f48999202ff71775d6912"},"service_rating":"4.9","shop_id":"5661CCA1EC94B09812562DA422607604","shop_name":"牛约堡-手作牛肉汉堡（紫金港店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i3\/2207644033664\/O1CN01FcYK1E1cwA6rWJaSa_!!2207644033664-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3532002","commission":"789","commission_rate":"0.06","daily_remain_stock":9,"daily_stock":10,"end_time":1719763199,"reward_cent":"1700","reward_threshold_cent":"2200","start_time":1711269934}]},"category_1_id":"239","category_1_name":"甜点饮品","delivery_distance":1478,"delivery_price_cent":0,"delivery_time":35,"indistinct_monthly_sales":"500+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=e3003dc3653947deb1eef56d0fa36bbd"},"service_rating":"5.0","shop_id":"5736A54B9E9DACD2639C3361A75EF634","shop_name":"雀巢冰淇淋生日蛋糕（西湖店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i4\/2217656155637\/O1CN01CM4iEa1rVna1ZiE4r_!!2217656155637-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"4006006","commission":"211","commission_rate":"0.06","daily_remain_stock":3,"daily_stock":5,"end_time":1810223999,"reward_cent":"1200","reward_threshold_cent":"1400","start_time":1715617004}]},"category_1_id":"233","category_1_name":"小吃\/烧烤","delivery_distance":2218,"delivery_price_cent":2000,"delivery_time":25,"indistinct_monthly_sales":"5000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=f54ac401d0ee4696b6371d3edb7e5682"},"service_rating":"4.9","shop_id":"B48E09707A8EE49A252C97458EA82FF6","shop_name":"鹤岗小串·东北烧烤","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i1\/2216669324270\/O1CN01AJXjle1hPi5NciPau_!!2216669324270-0-koubei.jpg"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"136","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2200","start_time":1704988800}]},"category_1_id":"233","category_1_name":"小吃\/烧烤","delivery_distance":1782,"delivery_price_cent":2000,"delivery_time":30,"indistinct_monthly_sales":"100+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=d5027678c1b84f1dabf143f7557be0dd"},"service_rating":"5.0","shop_id":"DAF48CAD59056E084C5CE50DF9EB6878","shop_name":"糖可滋·冰糖葫芦·炒酸奶（印悦里店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i1\/2217224641058\/O1CN01xUMuza1JgbzaFNEFE_!!2217224641058-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"4140002","commission":"627","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1719763199,"reward_cent":"1000","reward_threshold_cent":"2000","start_time":1717689600}]},"category_1_id":"239","category_1_name":"甜点饮品","delivery_distance":3009,"delivery_price_cent":0,"delivery_time":180,"indistinct_monthly_sales":"64","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=b399160abaf24420ae92ae75f3fc77f9"},"service_rating":"4.8","shop_id":"DE33F1BC3AC44B01","shop_name":"幸福西饼生日蛋糕·下午茶（杭州店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i1\/2209476284711\/O1CN01idiam11kfgn1MS76C_!!2209476284711-0-koubei.jpg"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"142","commission_rate":"0.06","daily_remain_stock":8,"daily_stock":10,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"1800","start_time":1706170072}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":2890,"delivery_price_cent":0,"delivery_time":29,"indistinct_monthly_sales":"900+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=de60969e3a2640e2b4d33950f1d536a5"},"service_rating":"4.9","shop_id":"8C9B4DD271482BF93EAF9B7544FCEE39","shop_name":"咱家纯手工水饺（拱墅区万达店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i4\/2216832290265\/O1CN01LrJOUm1DpPsQI1c2s_!!2216832290265-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"152","commission_rate":"0.06","daily_remain_stock":2,"daily_stock":10,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"1000","start_time":1714441989}]},"category_1_id":"220","category_1_name":"中式菜系","delivery_distance":3047,"delivery_price_cent":2000,"delivery_time":33,"indistinct_monthly_sales":"1000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=22e37063b096499987431cace9e849eb"},"service_rating":"4.9","shop_id":"FE71E3EBCD2F229C4F998A783F8F35AC","shop_name":"萨瓦玛·阿拉伯健康餐（拱墅万达店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2217589417862\/O1CN01CFvrJv27wqowxaidP_!!2217589417862-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"161","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2400","start_time":1704506773}]},"category_1_id":"239","category_1_name":"甜点饮品","delivery_distance":4210,"delivery_price_cent":2000,"delivery_time":46,"indistinct_monthly_sales":"24","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=a0015bc17ce84869a445c186d395644d"},"service_rating":"0.0","shop_id":"0738187F9826F6B1089CC07E6C277E44","shop_name":"墨咖啡 mo’s cafe","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i4\/2215978802290\/O1CN01oKUuEm1SmrqHlQwFK_!!2215978802290-0-koubei.jpg"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"155","commission_rate":"0.06","daily_remain_stock":8,"daily_stock":8,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"3000","start_time":1713888000}]},"category_1_id":"1242","category_1_name":"香锅火锅","delivery_distance":4188,"delivery_price_cent":1500,"delivery_time":36,"indistinct_monthly_sales":"4000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=efb816772a474384835bfebf2767be07"},"service_rating":"4.8","shop_id":"D68E55F35638A81E8300FFA9D0D72A33","shop_name":"鑫川香麻辣香锅·麻辣烫（文一路店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2215827243104\/O1CN01zfWB2m1YngLkcAbat_!!2215827243104-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"195","commission_rate":"0.06","daily_remain_stock":4,"daily_stock":5,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"2500","start_time":1714492800}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":5619,"delivery_price_cent":0,"delivery_time":40,"indistinct_monthly_sales":"1000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=1f6fb03969f24d708363404b97faa431"},"service_rating":"4.82","shop_id":"5FD6F389270C9B5C95E5A541205FF7B6","shop_name":"牛约堡-手作牛肉汉堡（西溪店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2215815736647\/O1CN01p2rafH1yyNZi7TSPl_!!2215815736647-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"167","commission_rate":"0.06","daily_remain_stock":8,"daily_stock":10,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"1000","start_time":1714441989}]},"category_1_id":"220","category_1_name":"中式菜系","delivery_distance":5551,"delivery_price_cent":0,"delivery_time":41,"indistinct_monthly_sales":"1000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=4ca410618fa34f66bfff54a86a93dc58"},"service_rating":"5.0","shop_id":"D129D8AA699F2B8B8300FFA9D0D72A33","shop_name":"萨瓦玛·阿拉伯健康餐（西溪银泰店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i1\/2217681490893\/O1CN01c3RkDG1IT2dDVfpZn_!!2217681490893-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"171","commission_rate":"0.06","daily_remain_stock":8,"daily_stock":10,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"1000","start_time":1715097600}]},"category_1_id":"220","category_1_name":"中式菜系","delivery_distance":5669,"delivery_price_cent":0,"delivery_time":38,"indistinct_monthly_sales":"900+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=6c03ca1568ff41428f4b33fe166bc095"},"service_rating":"5.0","shop_id":"E1890ECA981E02356A1CE279B9D14C4A","shop_name":"煲个椰子鸡（西溪银泰店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i1\/2215580287306\/O1CN011Tg4xv23qCWAYl2mF_!!2215580287306-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"157","commission_rate":"0.06","daily_remain_stock":0,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2200","start_time":1704470400}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":5482,"delivery_price_cent":1500,"delivery_time":42,"indistinct_monthly_sales":"200+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=87d1118fe7da47c79acb635a07e5a037"},"service_rating":"4.88","shop_id":"E171BB932E5B6A3C1C1D70E957AA8645","shop_name":"陇上秦轩西安biangbiang面·肉夹馍（城北万象城店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i4\/2217087921690\/O1CN01RojLf61OM4INWFBCu_!!2217087921690-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"192","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2400","start_time":1704556800}]},"category_1_id":"239","category_1_name":"甜点饮品","delivery_distance":5134,"delivery_price_cent":2000,"delivery_time":45,"indistinct_monthly_sales":"47","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=8ec4ea4c4c774ef9bdfc25b7af0e332b"},"service_rating":"5.0","shop_id":"FCB49855626D213F252C97458EA82FF6","shop_name":"杭一末咖啡EMoment（大兜路店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2217082875597\/O1CN01MRuWoS1rDTgk6g7yh_!!2217082875597-0-koubei.jpg"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"217","commission_rate":"0.06","daily_remain_stock":4,"daily_stock":5,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"2500","start_time":1714492800}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":5518,"delivery_price_cent":2000,"delivery_time":40,"indistinct_monthly_sales":"1000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=b15763af21a5485ea4a49d18d9bf7d5f"},"service_rating":"4.97","shop_id":"96F2A9FA2A52BD00BC88949CF4C024BA","shop_name":"牛约堡-手作牛肉汉堡（杭州上塘店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2217783887304\/O1CN01blU2Qy23pHoV5SU1O_!!2217783887304-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"3890002","commission":"165","commission_rate":"0.06","daily_remain_stock":6,"daily_stock":10,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"1000","start_time":1715011200}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":5581,"delivery_price_cent":2000,"delivery_time":48,"indistinct_monthly_sales":"500+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=9b984490f5cc4fb6afdfa730b3f3d3a6"},"service_rating":"4.7","shop_id":"DC9C1A4BF36A79F39AF31C60198333F9","shop_name":"超级泰·泰式麻辣烫（西溪天街店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i3\/2216989768218\/O1CN01pv8Ilf2AZtlqYXTLI_!!2216989768218-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"213","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2400","start_time":1704505848}]},"category_1_id":"239","category_1_name":"甜点饮品","delivery_distance":5206,"delivery_price_cent":2000,"delivery_time":48,"indistinct_monthly_sales":"34","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=2c80ab8af77040efb2baf4910c0c44f3"},"service_rating":"0.0","shop_id":"8EA38F16029EC4F03EAF9B7544FCEE39","shop_name":"有醴YOULI·咖啡（绿地商务中心店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2216547656258\/O1CN01GJQwcI1w6DXkUQ5oy_!!2216547656258-2-koubei.png"},{"activities":{"review_bwc_activity":[{"activity_id":"2932001","commission":"765","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1719590399,"reward_cent":"1000","reward_threshold_cent":"2400","start_time":1704556800}]},"category_1_id":"220","category_1_name":"中式菜系","delivery_distance":5174,"delivery_price_cent":5000,"delivery_time":50,"indistinct_monthly_sales":"97","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=c76c8d16cd0a4c10ab90646265d5d246"},"service_rating":"4.5","shop_id":"EDC8221128455E42E1A3519719FB8E9B","shop_name":"沈家门海鲜（信义坊店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i2\/2217150734050\/O1CN01IpwfDD1fmwyl0nyzZ_!!2217150734050-0-koubei.jpg"},{"activities":{"review_bwc_activity":[{"activity_id":"3894001","commission":"202","commission_rate":"0.06","daily_remain_stock":5,"daily_stock":5,"end_time":1745423999,"reward_cent":"800","reward_threshold_cent":"2500","start_time":1714492800}]},"category_1_id":"207","category_1_name":"快餐便当","delivery_distance":5449,"delivery_price_cent":100,"delivery_time":45,"indistinct_monthly_sales":"1000+","link":{"wx_appid":"wxece3a9a4c82f58c9","wx_path":"commercialize\/pages\/route-middle-page\/index?scene=c99a203224bf490c8e9438c1c4b5f09f"},"service_rating":"4.92","shop_id":"26A74025DCC0BB0DF2372A6781EC94E3","shop_name":"牛约堡.手作牛肉汉堡（拱墅远洋店）","shop_picture":"https:\/\/img.alicdn.com\/\/imgextra\/i4\/2213955424514\/O1CN01PLjzdx1jDSldWKYRK_!!2213955424514-2-koubei.png"}]},"session_id":"alsc_unionopen_5cb3be0d1a264f03977aee230cd55371"},"request_id":"16kv4gpcp30qw"}}
    public function reviewbwcquery($lng,$lat,$session_id='',$search_content='',$page_size=10)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.storepromotion.reviewbwc.query';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param = [
          'pid' => $this->pid,
          'longitude' => $lng,
          'latitude' => $lat,
          'page_size' => $page_size,
          'sort_type' => 'distance_asc',
          // 'min_commission_rate' => 0.01,//店铺佣金比例下限，代表筛选店铺全店佣金大于等于0.01的店铺
          // 'filter_first_categories' => '',//以一级类目进行类目限定，以,或者|进行类目分隔
          // 'filter_one_point_five_categories' => '',//1.5级类目查询，以"|"分隔
          // 'filter_city_id' => '',//城市ID（经纬度范围覆盖多个城市时，精准召回）
        ];
        if ($search_content) {
          $param['search_content'] = $search_content;//搜索内容（店铺名）
        }
        if ($session_id) {
          $param['session_id'] = $session_id;//会话ID（分页场景首次请求结果返回，后续请求必须携带，服务根据同一个session_id的请求次数自动叠加翻页返回数据，直至分页结束，返回空）
        }
        $params = [];
        $query = array_merge($query,$param);
        $sign = $this->sign($query, []);
        $query['sign'] = $sign;
        $url = $this->url.'?'.http_build_query($query);
        // \think\Log::write('饿了么官方商家'.json_encode($param).$url);
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }


    //店铺详情
    public function reviewbwcdetail($shop_id,$activity_id)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.storepromotion.reviewbwc.detail.get';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param = [
          'pid' => $this->pid,
          'shop_id' => $shop_id,
          'activity_id' => $activity_id,
        ];
        $params = [];
        $query = array_merge($query,$param);
        $sign = $this->sign($query, []);
        $query['sign'] = $sign;
        $url = $this->url.'?'.http_build_query($query);
        // \think\Log::write('饿了么官方商家'.json_encode($param).$url);
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }


    /**
     * 锁定库存
     */
    public function stocklock($shop_id,$activity_id,$mobile,$outer_order_id)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.storepromotion.reviewbwc.stock.lock';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param = [
          'pid' => $this->pid,
          'shop_id' => $shop_id,
          'activity_id' => $activity_id,
          'mobile' => $mobile,
          'outer_order_id' => $outer_order_id,
        ];
        $params = [];
        $query = array_merge($query,$param);
        $sign = $this->sign($query, []);
        $query['sign'] = $sign;
        $url = $this->url.'?'.http_build_query($query);
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }


    /**
     * 锁定释放
     */
    public function stockrelease($lock_id)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.storepromotion.reviewbwc.stock.release';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param = [
          'lock_id' => $lock_id,
        ];
        $params = [];
        $query = array_merge($query,$param);
        $sign = $this->sign($query, []);
        $query['sign'] = $sign;
        $url = $this->url.'?'.http_build_query($query);
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }


    /**
     * 锁定释放
     */
    public function diagnose($lock_id,$order_id)
    {
        $this->url = 'https://eco.taobao.com/router/rest';
        $method = 'alibaba.alsc.union.eleme.storepromotion.reviewbwc.diagnose';
        $query = [
          'method' => $method,
          'app_key' => self::AppKey,
          // 'timestamp' => '2023-05-11 14:01:06',
          'timestamp' => date('Y-m-d H:i:s',$this->timestamp),
          'v' => self::version,
          'sign_method' => 'md5',
          'format' => 'json',
          'partner_id' => 'top-apitools',
        ];
        $param = [
          'lock_id' => $lock_id,
          'order_id' => $order_id,
        ];
        $params = [];
        $query = array_merge($query,$param);
        $sign = $this->sign($query, []);
        $query['sign'] = $sign;
        $url = $this->url.'?'.http_build_query($query);
        $header = [];
        $res = Http::get($url,$params,[],$header);
        return $res;
    }

}
